import utils.DBUtil as db
import utils.PltUtil as plt
import utils.DateUtil as dt
import numpy as np

def do_first():
    d_code = "300177"
    today = dt.get_current_date()
    last_year_today = dt.get_last_by_day(365)

    # 平均价格
    avg_price = get_avg_price(d_code, today, last_year_today)

    sql = "select final_price from his_data where d_name = '" + d_code + "' and d_date >= '" + str(
        last_year_today) + "' and d_date < '" + str(today) + "' ORDER BY d_date asc"

    datas = db.select_data(sql)
    
    # for data in datas:
    #     # 每一天的价格
    #     every_price = data.get('final_price')


# 获取过去一年的平均值
def get_avg_price(d_code, today, last_year_today):
    sql = "select AVG(final_price) from his_data where d_name = '" + d_code + "' and d_date < '" + str(
        today) + "' and d_date >= '" + str(last_year_today) + "'"
    avg_price = db.get_data(sql)
    return avg_price


# get_avg_price("300177")

do_first()
